using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;
using WPFTemplateLib.WpfConverters.Core;

namespace WPFTemplateLib.WpfConverters
{
	/// <summary>
	/// [转换器] 获取文件名
	/// </summary>
	public class GetFileNameConverter : ValueConverterBase
	{
		public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			string valueStr = value + "";
			if(string.IsNullOrWhiteSpace(valueStr))
			{
				return value;
			}

			return Path.GetFileName(valueStr);
		}

		public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return Binding.DoNothing;
		}
	}

	/// <summary>
	/// [转换器] 获取文件名(不包含扩展名)
	/// </summary>
	public class GetFileNameWithoutExtensionConverter : ValueConverterBase
	{
		public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			string valueStr = value + "";
			if(string.IsNullOrWhiteSpace(valueStr))
			{
				return value;
			}

			return Path.GetFileNameWithoutExtension(valueStr);
		}

		public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return Binding.DoNothing;
		}
	}
}
